﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LanShellManager.Models
{
    public class ShellCommandResultRepository:IShellCommandResultRepository
    {
        private ShellCommandsEntities entities;

        public ShellCommandResultRepository()
        {
            entities = new ShellCommandsEntities();
        }

        public List<ShellCommandResultVm> GetShellCommandsRunResults()
        {
            List<ShellCommandResultVm> results = new List<ShellCommandResultVm>();
            List<ShellCommandRun> runResults = entities.ShellCommandRuns.OrderByDescending(x=>x.ExecutionTime).ToList();
            foreach (var result in runResults)
            {
                results.Add(new ShellCommandResultVm()
                {
                    Id = result.Id,
                    ResultType = result.ResultType,CommandResult = result.CommandResult,
                    MachineName = result.MachineName, ExecutionTime = result.ExecutionTime
                });
            }
            return results;
        }
    }
}
